﻿using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;

namespace Marmat.Forms
{
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(DevExpress.XtraEditors.TreeListLookUpEdit))]
    public partial class TreeListBox : EditControl
    {
        public TreeListBox()
        {

            // 此调用是设计器所必需的。
            this.InitializeComponent();

            // 在 InitializeComponent() 调用之后添加任何初始化。
            this.BaseEdit = this.TreeListLookUpEdit1;
        }

        public new DevExpress.XtraEditors.TreeListLookUpEdit BaseControl
        {
            get
            {
                return (DevExpress.XtraEditors.TreeListLookUpEdit)this.BaseEdit;
            }
        }

        /// <summary>
        /// 获取或设置在下拉窗口中显示的数据源。
        /// </summary>
        /// <returns></returns>
        public new object DataSource
        {
            get => this.m_DataSource;
            set
            {
                this.m_DataSource = value;
                this.TreeListLookUpEdit1.Properties.DataSource = value;
                this.TreeListLookUpEdit1.Properties.TreeList.DataSource = value;
                this.TreeListLookUpEdit1.RefreshEditValue();
            }
        }

        private object m_DataSource;

        /// <summary>
        /// 获取或设置字段名，其值标识下拉列表行。
        /// </summary>
        /// <returns></returns>
        public string ValueMember
        {
            get => this.TreeListLookUpEdit1.Properties.ValueMember;
            set
            {
                this.TreeListLookUpEdit1.Properties.ValueMember = value;
                if (this.DataSource is object)
                {
                    this.DataSource = this.DataSource;
                }
            }
        }

        /// <summary>
        /// 获取或设置其值显示在编辑框中的字段。
        /// </summary>
        /// <returns></returns>
        public string DisplayMember
        {
            get => this.TreeListLookUpEdit1.Properties.DisplayMember;
            set
            {
                this.TreeListLookUpEdit1.Properties.DisplayMember = value;
                if (this.DataSource is object)
                {
                    this.DataSource = this.DataSource;
                }
            }
        }

        /// <summary>
        /// 获取或设置标识每个记录的父记录的数据源字段。
        /// </summary>
        /// <returns></returns>
        public string ParentFieldName
        {
            get => this.TreeListLookUpEdit1.Properties.TreeList.ParentFieldName;
            set => this.TreeListLookUpEdit1.Properties.TreeList.ParentFieldName = value;
        }

        /// <summary>
        /// 获取或设置惟一标识数据源中记录的键字段的名称。
        /// </summary>
        /// <returns></returns>
        public string KeyFieldName
        {
            get => this.TreeListLookUpEdit1.Properties.TreeList.KeyFieldName;
            set => this.TreeListLookUpEdit1.Properties.TreeList.KeyFieldName = value;
        }
    }
}